package com.ruoyi.business.factory.llm.user_type;

import cn.hutool.core.util.RandomUtil;
import com.ruoyi.business.domain.SysUserLoginCompany;
import com.ruoyi.business.factory.llm.AbstractUserTypeTemplate;
import com.ruoyi.business.mapper.SysUserLoginCompanyMapper;
import com.ruoyi.business.service.ISysUserLoginCompanyService;
import com.ruoyi.business.utils.OrderUtils;
import com.ruoyi.common.core.domain.entity.SysUser;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * app企业端
 *
 * @author 99
 * @className ChatGPTTemplate
 * @description TODO
 * @date 2023/4/17 11:48
 */
@RequiredArgsConstructor
@Service("app_company")
@Slf4j
public class AppCompanyTemplate extends AbstractUserTypeTemplate {

    private final ISysUserLoginCompanyService userLoginCompanyService;

    private final SysUserLoginCompanyMapper sysUserLoginCompanyMapper;

    /**
     * 通过短信注册
     *
     * @param phonenumber 手机号
     * @return
     */
    @Override
    public Boolean registerSms(String phonenumber) {
        SysUser sysUser = this.registerSmsBefore(phonenumber);
        // 具体用户类型表插入
        SysUserLoginCompany sysUserLoginCompany = new SysUserLoginCompany();
        sysUserLoginCompany.setRelevanceUserId(sysUser.getUserId());
        sysUserLoginCompany.setCompanyName("企业" + RandomUtil.randomString(8));
        sysUserLoginCompany.setCompanyAbbreviation(String.valueOf(OrderUtils.generateRandomNumber(null)));
        sysUserLoginCompany.setUserId(sysUser.getUserId());

        int insert = sysUserLoginCompanyMapper.insert(sysUserLoginCompany);
        return insert>0;
    }

    /**
     * 通过手机号查询对应用户
     *
     * @param phonenumber 手机号
     * @return
     */
    @Override
    public SysUser selectUserByPhonenumber(String phonenumber) {
        return sysUserLoginCompanyMapper.selectUserByPhone(phonenumber);
    }
}
